package hu.diploma.web.client.panels;

import hu.diploma.web.client.Messages;
import hu.diploma.web.client.WidgetFactory;
import hu.diploma.web.client.pages.Classification;
import hu.diploma.web.client.pages.ContactsPage;
import hu.diploma.web.client.pages.GroupPage;
import hu.diploma.web.client.pages.OpenForm;
import hu.diploma.web.client.pages.StatsPage;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.util.Padding;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout.VBoxLayoutAlign;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;
import com.google.gwt.core.client.GWT;

public class Menu extends ContentPanel {
	private static Menu instanse;
	private final Messages messages = GWT.create(Messages.class);

	public Menu() {
		setFrame(true);
		initWidget();

	}

	public void initWidget() {

		VBoxLayout layout = new VBoxLayout();
		layout.setPadding(new Padding(5));
		layout.setVBoxLayoutAlign(VBoxLayoutAlign.STRETCH);
		setLayout(layout);
		setHeading(messages.menu());

		Button openButton = new Button(messages.open());
		Button contactButton = new Button(messages.contact());
		Button groupButton = new Button(messages.groups());
		Button classificationButton = new Button(messages.classification());
		Button statsButton = new Button(messages.stats());
		Button teamsButton = new Button(messages.teamManage());

		add(openButton, new VBoxLayoutData(new Margins(0, 0, 5, 0)));
		add(contactButton, new VBoxLayoutData(new Margins(0, 0, 5, 0)));
		add(classificationButton, new VBoxLayoutData(new Margins(0, 0, 5, 0)));
		add(groupButton, new VBoxLayoutData(new Margins(0, 0, 5, 0)));
		add(teamsButton, new VBoxLayoutData(new Margins(0, 0, 5, 0)));
		add(statsButton, new VBoxLayoutData(new Margins(0, 0, 5, 0)));

		openButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				WidgetFactory.getCenterPanel().setWidget(OpenForm.getWidget());

			}

		});
		contactButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				WidgetFactory.getCenterPanel().setWidget(ContactsPage.getWidget());

			}

		});
		groupButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				WidgetFactory.getCenterPanel().setWidget(GroupPage.getWidget());

			}

		});
		classificationButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				WidgetFactory.getCenterPanel().setWidget(Classification.getWidget());

			}

		});
		statsButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				WidgetFactory.getCenterPanel().setWidget(StatsPage.getWidget());

			}

		});

	}

	public static Menu getWidget() {
		if (instanse == null) {
			instanse = new Menu();
		}
		return instanse;
	}

}
